package com.syw.service.impl;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.syw.dao.MaintainDao;
import com.syw.entity.SywMaintain;
import com.syw.entity.SywUser;
import com.syw.service.MaintainService;
@Service("maintainService")
public class MaintainServiceImpl implements MaintainService{
	@Autowired
	private MaintainDao maintainDao ;
	@Override
	public List<SywMaintain> findAll() {
		// TODO Auto-generated method stub
		return maintainDao.findAll();
	}

	@Override
	public List<SywMaintain> findDept(SywUser su) {
		// TODO Auto-generated method stub
		return maintainDao.findDept(su);
	}

	@Override
	public List<SywMaintain> findAppoint(SywUser su, String city, SywMaintain sywMaintain) throws Exception {
		// TODO Auto-generated method stub
	/*	Date date=null;
		if(begidate!=null){
			java.text.SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd ");
			date =  formatter.parse(begidate);
		}*/
		int id=Integer.parseInt(city);
		return maintainDao.findAppoint(su, id, sywMaintain);
	}

	@Override
	public void addMaintain(SywMaintain sm,SywUser su,String city) {
		// TODO Auto-generated method stub
		sm.setBegidate(new Date());
		sm.setSywDept(maintainDao.findDeptid(Integer.parseInt(city)));
		sm.setSywMaintainstate(maintainDao.findMid(Integer.parseInt(city)));
		sm.setSywUser(su);
		maintainDao.addMaintain(sm);
	}

	@Override
	public void updateMaintain(SywMaintain sm) {
		// TODO Auto-generated method stub
		SywMaintain sma=maintainDao.findMaintainId(sm);
		maintainDao.updateMaintain(sma);
	}

	@Override
	public void updateMaintains(SywMaintain sm) {
		// TODO Auto-generated method stub
		SywMaintain sma=maintainDao.findMaintainId(sm);
		maintainDao.updateMaintains(sma);
	}

}
